Azure Key Vault JavaScript
Recently created a project that used Azure AD for single sign-on, and I set up [[Cypress and MSAL SSO]] and came across a classic problem - how do I store and share the secrets across the team?
I've used Azure Key Vault before on a C# project and it worked really well, as it used your Microsoft account to check your permissions in the Azure AD and could automatically inject env variables into your code when running it.
Luckily there are some Azure provided libraries to handle this in JavaScript, and below is the file I used to grab and set some environment variables when running Cypress.
I was also considering writing a preinstall
script which just writes the variables to a file, but that comes with the risk of them being accidentally committed.
Requirements
It's worth noting that for this to work properly you also need Azure CLI installed. Once installed you should use az login
and make sure you're logged into an account with permissions to use the Key Vault.